package com.my.lucky.service;

import com.my.lucky.entity.WencaiKeyword;
import com.my.lucky.repository.WencaiKeywordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
public class WencaiKeywordService {

    @Autowired
    private WencaiKeywordRepository wencaiKeywordRepository;

    @Transactional
    public WencaiKeyword getOrCreateKeyword(String keyword) {
        WencaiKeyword existingKeyword = wencaiKeywordRepository.findByKeyword(keyword);
        if (existingKeyword != null) {
            return existingKeyword;
        }
        WencaiKeyword newKeyword = new WencaiKeyword();
        newKeyword.setKeyword(keyword);
        newKeyword.setCreateTime(LocalDateTime.now());
        return wencaiKeywordRepository.save(newKeyword);
    }
} 